# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cegui
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.8.7
pkgrel=1
pkgdesc="A free library providing windowing and widgets for graphics APIs/engines (mingw-w64)"
arch=('any')
url="http://cegui.org.uk"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "mercurial")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-devil"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-FreeImage"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-fribidi"
         "${MINGW_PACKAGE_PREFIX}-glew"
         "${MINGW_PACKAGE_PREFIX}-glfw"
         "${MINGW_PACKAGE_PREFIX}-glm"
         "${MINGW_PACKAGE_PREFIX}-irrlicht"
         "${MINGW_PACKAGE_PREFIX}-libepoxy"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-lua51"
         "${MINGW_PACKAGE_PREFIX}-ogre3d"
         "${MINGW_PACKAGE_PREFIX}-ois"
         "${MINGW_PACKAGE_PREFIX}-openexr"
         "${MINGW_PACKAGE_PREFIX}-pcre"
         "${MINGW_PACKAGE_PREFIX}-python2"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-SDL2_image"
         "${MINGW_PACKAGE_PREFIX}-tinyxml"
         #"${MINGW_PACKAGE_PREFIX}-tolua"
         "${MINGW_PACKAGE_PREFIX}-xerces-c"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/crayzedsgui/cegui-${pkgver}.tar.bz2"
        001-c++11-support.patch
        002-fix-finding-glew.patch
        003-fix-finding-directx.patch
        004-fix-dxerr-libname.patch
        005-fix-find-sdl2_image.patch
        006-fix-find-sdl2.patch
        007-load-proper-pixel-format.patch
        008-ogre-1.11-support.patch
        009-use-macros-for-changed-ogre-sharedptr.patch
        010-python-bindings.patch
        011-fix-tinyxml-parser.patch
        012-find-boost-1.67.patch
        013-samples-framework-ogre-1.11.patch
        014-fix-ogre-render.patch
        015-fix-ogre-link-libraries.patch)
sha256sums=('b351e8957716d9c170612c13559e49530ef911ae4bac2feeb2dacd70b430e518'
            '3fe46fea91debd245bcca7f7c07b1fc9f51ab12f63be3201f812eea8bef88cd0'
            '3aa712304267353afe103cd8efa5f6f7b87fa98423d77610716d15a425194f2e'
            '1ae821516efaeecce5b27579d5236b11b3eb8075d3e173d1b3b973e81c1ee22e'
            '4c22f176f0fa430eeaf2ac6b21d587c7e1f3c04d8d3c03e957a35a95f077531b'
            'cf67d0a5415bb6b8a994e0ce8cf4d065355309fabc53682b9eace6f0c48babeb'
            '4317c83156a230b5a207d439368b478ae9a6183c5dd219507f1e0f8440acf2b8'
            '8ee725e1a6e17e5eb06568e1481b3a78e1bdfeb5d97803ac59a6a6230687efe0'
            'c1c2f646260fce8331bcfb7f3875e445cc6eabdc54ac2bf7a0cb8f2821cd09c3'
            '631feca651c31020dfcfedb39f3a839b2cec4e863b5fa62c7f1f65dd145bbe77'
            '03889f048e77d6b04ef1b2f6679fc37852e573f3ff1386205ba3ad4604d21077'
            '9005c4adfed3a1bd0fb7f0acbf68d43e258826c3d4d04ca987cfb254e0b56349'
            'd14627416150c5a99660ec2f8942af3441953e8d0e198c087ba6b57b6e518bc6'
            '602394c622701133a808f108663ae454b418da27a27c2989fc7c70e3abd32cfb'
            '6ee91b2296e7fb515084549f02391a5a8206556f2cf9452ddf4052e423ca744b'
            '6ff5b315e90b6a916e1b293d3e9b85e73ed9280b046ee18c23053f0fb82a29a9')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/001-c++11-support.patch
  patch -p1 -i ${srcdir}/002-fix-finding-glew.patch
  patch -p1 -i ${srcdir}/003-fix-finding-directx.patch
  patch -p1 -i ${srcdir}/004-fix-dxerr-libname.patch
  patch -p1 -i ${srcdir}/005-fix-find-sdl2_image.patch
  patch -p1 -i ${srcdir}/006-fix-find-sdl2.patch
  patch -p1 -i ${srcdir}/007-load-proper-pixel-format.patch
  patch -p1 -i ${srcdir}/008-ogre-1.11-support.patch
  patch -p1 -i ${srcdir}/009-use-macros-for-changed-ogre-sharedptr.patch
  patch -p1 -i ${srcdir}/010-python-bindings.patch
  patch -p1 -i ${srcdir}/011-fix-tinyxml-parser.patch
  patch -p1 -i ${srcdir}/012-find-boost-1.67.patch
  patch -p1 -i ${srcdir}/013-samples-framework-ogre-1.11.patch
  patch -p1 -i ${srcdir}/014-fix-ogre-render.patch
  patch -p1 -i ${srcdir}/015-fix-ogre-link-libraries.patch
}

build() {
  rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
  DXSDK_DIR=${MINGW_PREFIX}/${MINGW_CHOST} \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCEGUI_LIB_INSTALL_DIR=lib \
    -DCEGUI_BUILD_PYTHON_MODULES=ON \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python2 \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} -j1 install
}
